package com.dms.modules.merchant.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;

@Data
@TableName("merchant")
@ApiModel(value = "Merchant对象", description = "商户")
public class Merchant implements UserDetails {
    
    @TableId(type = IdType.AUTO)
    @ApiModelProperty("商户ID")
    private Long id;
    
    @ApiModelProperty("关联的用户ID")
    private Long userId;
    
    @TableField(exist = false)
    @ApiModelProperty("用户名")
    private String username;
    
    @TableField(exist = false)
    @ApiModelProperty("密码")
    private String password;
    
    @TableField(exist = false)
    @ApiModelProperty("昵称")
    private String nickname;
    
    @TableField(exist = false)
    @ApiModelProperty("头像")
    private String avatar;
    
    @TableField(exist = false)
    @ApiModelProperty("邮箱")
    private String email;
    
    @TableField(exist = false)
    @ApiModelProperty("手机号")
    private String phone;
    
    @ApiModelProperty("状态：0-禁用 1-正常")
    private Integer status;
    
    @ApiModelProperty("店铺名称")
    private String shopName;
    
    @ApiModelProperty("店铺logo")
    private String shopLogo;
    
    @ApiModelProperty("店铺描述")
    @TableField("shop_description")
    private String shopDescription;
    
    @ApiModelProperty("营业执照号")
    private String businessLicense;
    
    @ApiModelProperty("法人姓名")
    private String legalPerson;
    
    @ApiModelProperty("联系电话")
    private String contactPhone;
    
    @ApiModelProperty("联系邮箱")
    private String contactEmail;
    
    @ApiModelProperty("商家等级")
    private Integer level;
    
    @ApiModelProperty("商家评分")
    private Double score;
    
    @ApiModelProperty("店铺公告")
    private String notice;
    
    @ApiModelProperty("营业执照图片")
    private String businessLicenseImage;
    
    @ApiModelProperty("法人身份证号")
    private String legalPersonIdCard;
    
    @ApiModelProperty("法人身份证正面")
    private String legalPersonIdCardFront;
    
    @ApiModelProperty("法人身份证反面")
    private String legalPersonIdCardBack;
    
    @ApiModelProperty("店铺地址")
    private String address;
    
    @ApiModelProperty("审核状态：0-待审核 1-通过 2-拒绝")
    private Integer auditStatus;
    
    @ApiModelProperty("审核意见")
    private String auditComment;
    
    @ApiModelProperty("审核时间")
    private Date auditTime;
    
    @ApiModelProperty("是否推荐：0-否 1-是")
    private Integer isRecommend;
    
    @ApiModelProperty("营业时间")
    private String businessHours;
    
    @ApiModelProperty("运费模板ID")
    private Long freightTemplateId;
    
    @ApiModelProperty("售后政策")
    private String afterSalePolicy;
    
    @ApiModelProperty("店铺协议")
    private String shopAgreement;
    
    @TableField(exist = false)
    @ApiModelProperty("角色ID")
    private Long roleId;
    
    @ApiModelProperty("创建时间")
    private Date createTime;
    
    @ApiModelProperty("更新时间")
    private Date updateTime;
    
    @TableLogic
    @ApiModelProperty("是否删除")
    private Integer deleted;
    
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.singletonList(new SimpleGrantedAuthority("ROLE_MERCHANT"));
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return status != null && status == 1;
    }
} 